#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#include "math_morph.h"

//typedef unsigned char pixel;

#define HEIGHT 20
#define WIDTH 10

int main(int argc, char** argv) {
	int i, j;

	EE *ee = (EE *)malloc(sizeof(EE));
	setType(ee, EE_CRUZ3X3);
	setMatrix(ee, getType(ee));
	pixel **ret, **ret1, **matrix;
	
	matrix = (pixel **)malloc(HEIGHT * sizeof(pixel*));

	for (i = 0; i < HEIGHT; i++) {
		matrix[i] = (pixel*)malloc(WIDTH * sizeof(pixel));
	}
	srand(time(NULL));
	for (i = 0; i < HEIGHT; i++) {
		for (j = 0; j < WIDTH; j++) {
			matrix[i][j] = rand();
		}
	}

	ret = dilate(matrix, ee, HEIGHT, WIDTH, 3, 3);
	
	for (i = 0; i < HEIGHT; i++) {
		for (j = 0; j < (WIDTH - 1); j++) {
			printf("%d\t", matrix[i][j]);
		}
		printf("%d\n", matrix[i][WIDTH - 1]);
	}
	
	printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	
	for (i = 0; i < HEIGHT; i++) {
		for (j = 0; j < (WIDTH - 1); j++) {
			printf("%d\t", ret[i][j]);
		}
		printf("%d\n", ret[i][WIDTH - 1]);
	}

	ret1 = erode(ret, ee, HEIGHT, WIDTH, 3, 3);
	
	printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	
	for (i = 0; i < HEIGHT; i++) {
		for (j = 0; j < (WIDTH - 1); j++) {
			printf("%d\t", ret1[i][j]);
		}
		printf("%d\n", ret1[i][WIDTH - 1]);
	}
	
	free(ret);
	free(ret1);
	free(matrix);
	
	return 0;
}
